package src.model.gameWorld.pathfinding;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.List;

import src.model.gameWorld.Position;

/**
 * <b>Overview</b>
 * Represents a path to follow to get from one map PathfindingLocation to another.
 *
 * <b>Responsibilities</b>
 * Get the next position in the path or iterate over all positions in the path.
 *
 * <b>Collaborators</b>
 * Position - Subcontractor: Positions handle the actual coordinates of each location on the map that the Path leads to.
 *
 * <b>Implementor</b> - Bruce
 * <b>Tester</b> - Tim
 *
 * @author Bruce
 */
public final class Path implements Iterable<Position>
{
	/**
	 * The queue of Locations one must pass through to get from the start to the end PathfindingLocation.
	 * @uml.property   name="pathfindingLocations"
	 * @uml.associationEnd   multiplicity="(0 -1)" elementType="map.pathfinding.PathfindingLocation"
	 */
	private Queue<Position> pathfindingLocations = new LinkedList<Position>();

	/**
	 * Creates a new Path.
	 *
	 * @param pathfindingLocations the list of Locations required to move from the starting PathfindingLocation to the destination PathfindingLocation.  The order of the list determines when each PathfindingLocation is required: the first element should be the starting PathfindingLocation.  A <code>null</code> argument results in an empty Path.
	 */
	public Path(List<Position> pathfindingLocations)
	{
		if(pathfindingLocations != null)
			for(Position l : pathfindingLocations)
				this.pathfindingLocations.add(l);
	}

	/**
	 * @return the next PathfindingLocation in this Path or <code>null</code> if the end of the Path has been reached.
	 */
	public Position next()
	{
		return pathfindingLocations.poll();
	}

	/**
	 * @return <code>true</code> if this Path still contains movement Locations or <code>false</code> otherwise.
	 */
	public boolean hasNext()
	{
		return !pathfindingLocations.isEmpty();
	}

	/* (non-Javadoc)
	 * @see java.lang.Iterable#iterator()
	 */
	public Iterator<Position> iterator()
	{
		return pathfindingLocations.iterator();
	}
}